<template>
  <view>
    <nut-navbar @on-click-back="back" @on-click-title="title" title="订单详情">
      <template #left>
        <div>返回</div>
      </template>
      <template #right>
        <nut-icon class="right" name="share-n"></nut-icon>
      </template>
    </nut-navbar>

    <view @click="add">
      {{ getNumbers }}
    </view>
    <view @click="obj">
      {{ apiUserInfo.name }} 对象属性-变更测试 {{ apiUserInfo.age }}
    </view></view
  >
</template>

<script>
import Taro, { useReady } from "@tarojs/taro";
export default {
  components: {},
  data() {
    return {
      apiUserInfo: {},
    };
  },
  created() {
    this.apiUserInfo = this.$store.apiUserInfo;
    // this.login()
  },
  computed: {
    getNumbers() {
      return this.$store.getters.getCount;
    },
    apiUserInfo() {
      return this.$store.getters.getApiUserInfo;
    },
  },
  methods: {
    async login() {
      console.log(this.ajax);
      // this.ajax.
      var th = this;
      Taro.getUserProfile({
        lang: "zh_CN",
        desc: "获取你的昵称、头像、地区及性别",
        success: (response) => {
          console.log(response);
          var { nickName, avatarUrl } = response;
          const userInfo = response.userInfo;
          console.log("getUserProfile", userInfo);
          Taro.login({
            success(res) {
              console.log("Taro.login()===>", res);
              var { code } = res;
              if (code) {
                th.ajax.get(th.ajax.api.wxLogin, { appid: "wx9ada1ca5bc5f4063", code, nickName, avatarUrl, }).then((res) => {
                    console.log("登录后的响应", res);
                  });
              } else {
                console.log("登录失败！" + res.errMsg);
              }
            },
          });
          Taro.setStorageSync("userInfo", { userInfo });
          Taro.getStorage({
            key: "userInfo",
            success(res) {
              console.log("缓存数据", res);
            },
          });
        },
        fail: () => {
          //拒绝授权
          console.error("您拒绝了请求");
        },
      });
    },
    add() {
      this.$store.dispatch("addAction", Number(1));
    },
    obj() {
      this.$store.dispatch("asyncApiUserInfo", { name: "WZXX", age: 11 });
    },
  },
};
</script>

<style lang="scss">
</style>
